import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import WebSocketComponent from "@runtime/module/WebSocket/WebSocketComponent";

/**
 * UsageCameraComponent组件
 */
export default class UsageCameraComponent {
    private static instance: UsageCameraComponent = new UsageCameraComponent();
    /**
     * UsageCameraComponent组件
     */
    public static get Default(): UsageCameraComponent {
        return this.instance;
    }

    constructor() {
        window.addEventListener('unload', this.Dispose.bind(this));
    }

    Dispose() {
        window.removeEventListener('unload', this.Dispose);
    }

    public async UpdateAsync(instanceId: number, offset: number, size: number, minSize: number, maxSize: number): Promise<boolean> {
        const response = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.MillimeterWaveRadarUsageCameraUpdateRequest(instanceId, offset, size, minSize, maxSize));
        return response.Error == 0;
    }

    public async ChangeTargetAsync(instanceId: number): Promise<boolean> {
        const response = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.MillimeterWaveRadarUsageCameraChangeTargetRequest(instanceId));
        return response.Error == 0;
    }
}